﻿using System.Linq;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Room Type Repository
    /// </summary>
    public class RoomTypeRepository : IRoomTypeRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Room Type Details by Title
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<RoomType> FindRoomTypeByName(string strQuery)
        {
            return _db.RoomTypes.Where(d => d.RoomTypeName.Contains(strQuery));
        }

        /// <summary>
        /// Get All Room Type
        /// </summary>
        /// <returns></returns>
        public IQueryable<RoomType> FindAllRoomType()
        {
            return _db.RoomTypes;
        }

        /// <summary>
        /// Get Room Type by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public RoomType GetRoomTypeById(int id)
        {
            return _db.RoomTypes.SingleOrDefault(d => d.RoomTypeId == id);
        }

        /// <summary>
        /// Add Room Type in the Database
        /// </summary>
        /// <param name="roomType"></param>
        public void Add(RoomType roomType)
        {
            _db.RoomTypes.AddObject(roomType);
        }

        /// <summary>
        /// Delete Room Type from Database
        /// </summary>
        /// <param name="roomType"></param>
        public void Delete(RoomType roomType)
        {
            _db.RoomTypes.DeleteObject(roomType);
        }

        /// <summary>
        /// Save Room Type in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}